package com.kang.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kang.entity.SysLoginLog;
import com.kang.service.SysLoginLogService;
import com.kang.util.WebResponse;
import com.kang.vo.SysLoginLogQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "登录日志接口")
@RestController
@RequestMapping("/admin/system/sysLoginLog")
@Slf4j
public class SysLoginLogController {

    @Autowired
    private SysLoginLogService sysLoginLogService;


    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public WebResponse index(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page, @ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable Integer limit,
            @ApiParam(name = "sysLoginLogVo", value = "查询对象", required = false) SysLoginLogQueryVo sysLoginLogQueryVo) {
        try {
            Page<SysLoginLog> pageParam = new Page<>(page, limit);
            return WebResponse.resSuccess("获取分页列表成功",sysLoginLogService.selectPage(pageParam, sysLoginLogQueryVo));
        } catch (Exception e) {
            log.info("获取分页列表失败",e);
            return WebResponse.resFail("获取分页列表失败",null);
        }
    }

    @ApiOperation(value = "根据ID获取登录日志失败")
    @GetMapping("get/{id}")
    public WebResponse get(@PathVariable Integer id) {
        try {
            return  WebResponse.resSuccess("根据ID获取登录日志成功",sysLoginLogService.getById(id));
        } catch (Exception e) {
            log.info("根据ID获取登录日志失败",e);
            return WebResponse.resFail("根据ID获取登录日志失败",null);
        }
    }

}
